<template>
  <div class="waprs">
    <div class="logo_info">
      <img :src="iconUrl" alt="" class="logo" />
      <div class="name">小熊抢外观</div>
    </div>
    <div class="warp">
      <div class="login_letf">
        <div class="login_n">
          <img src="../assets/image/logo.jpg" alt="" class="login_n_img" />
        </div>
      </div>
      <div class="login_night" v-if="isLogin">
        <div class="login_content">
          <div class="title">密码登录</div>
          <div class="input_title" style="margin-top: 32px">用户名</div>
          <div class="input_info">
            <img :src="icon" alt="" class="icon" v-if="!isShowIcon" />
            <img :src="icon1" alt="" class="icon" v-else />
            <img :src="close" alt="" class="icon close" v-if="isShowClose" @click="btnClose" />
            <el-input ref="input" placeholder="请输入用户名" v-model="phone" maxlength="20" @focus="focus" @input="input"
              @blur="blur">
            </el-input>
          </div>
          <div class="input_title" style="margin-top: 16px">密码</div>
          <div class="input_info">
            <img :src="icon2" alt="" class="icon" v-if="!isShowIcon1" />
            <img :src="icon3" alt="" class="icon" v-else />
            <img :src="close" alt="" class="icon close" v-if="isShowClose1" @click="btnClose1" style="left: 280px" />
            <el-input ref="input1" placeholder="请输入密码" v-model="moble" maxlength="11" @focus="focus1" @input="input1"
              @blur="blur1" show-password class="mobile-input">
            </el-input>
          </div>
          <el-button type="primary" :disabled="phone && moble ? false : true" @click="btnLogin">登录</el-button>
          <div style="display: flex; justify-content: space-between;">
            <div class="xuan-z" @click="btnEnroll">注册账号</div>
            <el-checkbox v-model="checked" style="margin-top: 5px;">记住密码</el-checkbox>
          </div>
        </div>
      </div>
      <div class="login_night" v-else>
        <enroll @logins="logins"></enroll>
      </div>
    </div>
  </div>
</template>

<script>
import { post } from '@/utils/request'
import enroll from './enroll'
import store from '@/store'
const { ipcRenderer } = require('electron')
export default {
  components: {
    enroll
  },
  data() {
    return {
      iconUrl: require('../../src/assets/image/logo.jpg'),
      icon: require('../../src/assets/image/hui-phone.png'),
      icon1: require('../../src/assets/image/phone.png'),
      close: require('../../src/assets/image/close.png'),
      icon2: require('../../src/assets/image/mobel-h.png'),
      icon3: require('../../src/assets/image/moble.png'),
      isShowIcon: false,
      isShowClose: false,
      isShowIcon1: false,
      isShowClose1: false,
      phone: '',
      moble: '',
      isLogin: true,
      userInfo: {},
      num: '',
      comPanyInfo: {},
      checked: false
    }
  },
  created() {
    let data = ipcRenderer.sendSync('get-data', 'userInfo')
    if (data.checked) {
      console.log(1111, data.checked)
      this.moble = data.moble
      this.phone = data.phone
    } else {
      this.moble = ''
      this.phone = ''
    }
  },
  methods: {
    input(e) {
      this.phone = e
      if (this.phone) {
        this.isShowIcon = true
        this.isShowClose = true
      } else {
        this.isShowClose = false
      }
    },
    focus() {
      this.isShowIcon = true
      if (this.phone) {
        this.isShowClose = true
      }
    },
    blur() {
      setTimeout(() => {
        this.isShowClose = false
      }, 300)
      if (!this.phone) {
        this.isShowIcon = false
      }
      this.isAutofocus = true
    },
    btnClose() {
      this.phone = ''
      this.$nextTick(() => {
        this.$refs.input.focus()
      })
    },
    btnClose1() {
      this.moble = ''
      this.$nextTick(() => {
        this.$refs.input1.focus()
      })
    },
    input1(e) {
      this.moble = e
      if (this.moble) {
        this.isShowIcon1 = true
        this.isShowClose1 = true
      } else {
        this.isShowClose1 = false
      }
    },
    focus1() {
      this.isShowIcon1 = true
      if (this.moble) {
        this.isShowClose1 = true
      }
    },
    blur1() {
      setTimeout(() => {
        this.isShowClose1 = false
      }, 300)
      if (!this.moble) {
        this.isShowIcon1 = false
      }
      this.isAutofocus1 = true
    },
    // 登录
    async btnLogin() {
      if (this.checked) {
        let infor = {
          phone: this.phone,
          moble: this.moble,
          checked: this.checked
        }
        ipcRenderer.send('setStore', 'userInfo', infor)
      } else {
        let infor = {
          phone: this.phone,
          moble: this.moble,
          checked: false
        }
        ipcRenderer.send('setStore', 'userInfo', infor)
      }
      await post(
        `/user/user/login`,
        {
          username: this.phone,
          password: this.moble
        },
        'application/json;charset=utf-8'
      ).then((res) => {
        if (res.status == '200') {
          store.commit('updatePageType', res.data.auth_token)
          store.commit('getUserInfo', res.data)
          localStorage.setItem('token', res.data.auth_token)
          ipcRenderer.send('setStore', 'ticketList', JSON.stringify([]))
          this.$router.push({
            path: '/home'
          })
        } else {
          this.$message.error(res.info)
        }
      })
    },
    // 切换注册
    btnEnroll() {
      this.isLogin = false
    },
    logins() {
      this.isLogin = true
    },
  }
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
.waprs {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-image: url('../assets/image/login-bg.png');
  background-size: cover;
  position: relative;
}

.logo_info {
  position: absolute;
  display: flex;
  align-items: center;
  top: 51px;
  left: 51px;

  .logo {
    width: 45px;
    height: 45px;
  }

  .name {
    font-size: 22px;
    font-family: MiSans-Regular;
    font-weight: bold;
    color: #1a1a1a;
    margin-left: 12px;
  }
}

.warp {
  display: flex;
  justify-content: center;
  align-items: center;
}

.login_letf {
  .login_n {
    display: flex;
    align-items: center;
    margin-top: 43px;

    .login_n_img {
      width: 266px;
      height: 268px;
    }

    .login_n_tit {
      display: flex;
      flex-direction: column;
      align-items: center;
      margin-left: 16px;
      color: #000000;

      .login_n_tit_1 {
        font-size: 20px;
        font-family: MiSans-Regular;
        font-weight: bold;
        line-height: 28px;
        letter-spacing: 1px;
        margin-bottom: 8px;
      }

      .login_n_tit_2 {
        font-size: 14px;
        font-family: PingFang-SC, PingFang-SC;
        font-weight: 400;
        line-height: 20px;
        letter-spacing: 2px;
      }
    }
  }
}

.login_night {
  width: 440px;
  height: 488px;
  background: #ffffff;
  box-shadow: 0px 2px 14px 0px #eaebee;
  border-radius: 12px;
  margin-left: 132px;

  .login_content {
    width: 336px;
    margin: auto;
  }

  .input_title {
    line-height: 20px;
    margin-bottom: 8px;
  }

  .title {
    font-size: 20px;
    font-family: MiSans-Regular;
    font-weight: bold;
    color: #1a1a1a;
    margin-top: 56px;
    line-height: 28px;
    text-align: center;
  }

  .input_info {
    position: relative;

    .icon {
      width: 16px;
      height: 16px;
      z-index: 1;
      left: 16px;
      top: 12px;
      position: absolute;
    }

    .close {
      left: 304px;
      cursor: pointer;
    }

    :deep(.el-input) {
      height: 40px;
      border-radius: 6px;
      font-size: 14px;
      font-family: PingFangSC, PingFang SC;
      font-weight: 400;
      color: #1a1a1a;
    }

    :deep(.el-input__inner) {
      padding-left: 32px;
    }

    :deep(input::-webkit-input-placeholder) {
      font-size: 14px;
      font-family: PingFangSC, PingFang SC;
      font-weight: 400;
      color: #9d9da2;
    }

    .mobile-input {
      :deep(.el-input__wrapper) {
        padding-right: 16px;
      }
    }
  }

  :deep(.el-button) {
    width: 100%;
    height: 40px;
    border-radius: 6px;
    margin-top: 32px;
  }

  .xuan-z {
    // margin-left: 32px;
    margin-top: 10px;
    cursor: pointer;
  }

  .warning {
    font-size: 12px;
    font-family: PingFangSC, PingFang SC;
    font-weight: 400;
    color: #9d9da2;
    margin-left: 78px;
    margin-top: 54px;
  }
}

:deep(.el-checkbox__input.is-checked .el-checkbox__inner::after) {
  border-color: #ffffff;
}

.drop-wrapper {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  z-index: 99;
  background: #ffffff;
  opacity: 0.7;
  // filter: blur(26px);
  padding-top: 125px;

  .upload-info {
    height: 56px;
    line-height: 56px;
    background: #e5efff;
    border: 1px dashed #075eed;
    text-align: center;
  }
}
</style>
